package com.css.bjdt_report.cell.service;

import org.nutz.dao.Dao;
import org.nutz.dao.Sqls;
import org.nutz.dao.sql.Sql;
import org.nutz.dao.sql.SqlCallback;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.css.bjdt_report.cell.entity.VarParam;
@Service
public class CustomSqlService {
	@Autowired
	private Dao dao;
	
	public Sql executeSql(String sqlStr, SqlCallback callback, VarParam... varparams) {
		Sql sql = Sqls.create(sqlStr);
		if(varparams != null){
			for (VarParam varparam : varparams) {
				String varKey = varparam.getVarKey();
				String varValue = varparam.getVarValue();
				String paramKey = varparam.getParamKey();
				String paramValue = varparam.getParamValue();
				if (varKey != null && varValue != null) {
					sql.vars().set(varKey, varValue);
				}
				if (paramKey != null && paramValue != null) {
					sql.params().set(paramKey, paramValue);
				}
			}			
		}
		if (callback != null) {
			sql.setCallback(callback);
		}
		dao.execute(sql);
		return sql;
	}
}
